package com.ruoyi.eservice.service.impl;

import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.base.BaseService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.eservice.mapper.NoticePlaceMapper;
import com.ruoyi.eservice.pojo.entity.NoticePlace;
import com.ruoyi.eservice.service.INoticePlaceService;

/**
 * 核酸点Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-11
 */
@Service
public class NoticePlaceServiceImpl extends BaseService implements INoticePlaceService
{
    @Autowired
    private NoticePlaceMapper noticePlaceMapper;

    /**
     * 查询核酸点
     *
     * @param noticePlaceId 核酸点主键
     * @return 核酸点
     */
    @Override
    public NoticePlace selectNoticePlaceByNoticePlaceId(Long noticePlaceId)
    {
        return noticePlaceMapper.selectById(noticePlaceId);
    }

    /**
     * 查询核酸点列表
     *
     * @param noticePlace 核酸点
     * @return 核酸点
     */
    @Override
    public List<NoticePlace> selectNoticePlaceList(NoticePlace noticePlace)
    {
        QueryWrapper<NoticePlace> queryWrapper = createSelWrapper(NoticePlace.class);
        queryWrapper.lambda()
                .like(StringUtils.isNotNull(noticePlace.getNatName()), NoticePlace::getNatName, noticePlace.getNatName())
                .like(StringUtils.isNotEmpty(noticePlace.getNatStreet()), NoticePlace::getNatStreet, noticePlace.getNatStreet())
                .like(StringUtils.isNotEmpty(noticePlace.getNatPlace()), NoticePlace::getNatPlace, noticePlace.getNatPlace())
                .le(StringUtils.isNotNull(noticePlace.getNatStarttime()), NoticePlace::getNatStarttime, noticePlace.getNatStarttime())
                .gt(StringUtils.isNotNull(noticePlace.getNatEndtime()), NoticePlace::getNatEndtime, noticePlace.getNatEndtime())
                .eq(StringUtils.isNotNull(noticePlace.getNaNoticeId()), NoticePlace::getNaNoticeId, noticePlace.getNaNoticeId())
                .eq(StringUtils.isNotEmpty(noticePlace.getDelFlag()), NoticePlace::getDelFlag, noticePlace.getDelFlag())
        ;
        return noticePlaceMapper.selectList(queryWrapper);
    }

    /**
     * 新增核酸点
     *
     * @param noticePlace 核酸点
     * @return 结果
     */
    @Override
    public int insertNoticePlace(NoticePlace noticePlace)
    {
        noticePlace.setCreateBy(SecurityUtils.getUsername());
        noticePlace.setCreateTime(DateUtils.getNowDate());
        noticePlace.setUpdateBy(SecurityUtils.getUsername());
        noticePlace.setUpdateTime(DateUtils.getNowDate());
        int rows = noticePlaceMapper.insert(noticePlace);
        return rows;
    }

    /**
     * 修改核酸点
     *
     * @param noticePlace 核酸点
     * @return 结果
     */
    @Override
    public int updateNoticePlace(NoticePlace noticePlace)
    {
        noticePlace.setUpdateBy(SecurityUtils.getUsername());
        noticePlace.setUpdateTime(DateUtils.getNowDate());

        return noticePlaceMapper.updateById(noticePlace);
    }

    /**
     * 批量删除核酸点
     *
     * @param noticePlaceIds 需要删除的核酸点主键
     * @return 结果
     */
    @Override
    public int deleteNoticePlaceByNoticePlaceIds(Long[] noticePlaceIds)
    {
        return noticePlaceMapper.deleteBatchIds(Arrays.asList(noticePlaceIds));
    }

    /**
     * 删除核酸点信息
     *
     * @param noticePlaceId 核酸点主键
     * @return 结果
     */
    @Override
    public int deleteNoticePlaceByNoticePlaceId(Long noticePlaceId)
    {
        return noticePlaceMapper.deleteById(noticePlaceId);
    }
}
